﻿using System;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Audio;

public class GameplayScreen : GameScreen
{
    ContentManager content;

    private bool startRandom;

    private int map;

    private String name;
    private int charisma, intelligence, perception;
    private Day day, maxDay;

    public GameplayScreen(Day day, Day maxDay, String name, int charisma, int intelligence, int perception)
    {
        this.day = day;
        this.maxDay = maxDay;
        this.map = 0;
        this.name = name; this.charisma = charisma; this.intelligence = intelligence; this.perception = perception;

		startRandom = false;

        TransitionOnTime = TimeSpan.FromSeconds(1.5);
        TransitionOffTime = TimeSpan.FromSeconds(0.1);
    }

    public override void LoadContent()
    {
        content = ScreenManager.Game.Content;

        GameSession.StartNewSession(ScreenManager, this, name, charisma, intelligence, perception, day, maxDay);

        //GameSession.LoadMap(0);

        GameSession.LoadContent(content);

        ScreenManager.Game.ResetElapsedTime();

    }

    bool showDay = true;

    public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
    {
        base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

       	if (!Globals.IsPaused)
       	{
        	GameSession.Update(gameTime);
		}
        if (GameSession.ShowDay)
        {
            ScreenManager.AddScreen(new DayMessageScreen((int)GameSession.ActualDay));
            GameSession.ShowDay = false;
        }
        if(!Globals.FirstTime && Globals.FirstMove)
        {
            ScreenManager.AddScreen(new TutorialScreen(TutorialScreen.TutorialKind.MOVE));
            Globals.FirstMove = false;
        }
    }

    public override void HandleInput()
    {
        if (InputManager.IsActionTriggered(InputManager.Action.Back))
            GameSession.ScreenManager.AddScreen(new PauseScreen());
    }

    public override void UnloadContent()
    {
        startRandom = false;

        base.UnloadContent();
    }

    public override void Draw(GameTime gameTime)
    {
        SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

        GameSession.Draw(gameTime);
    }
}
